package test.wechat.rest;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import lodsve.wechat.beans.User;
import lodsve.wechat.enums.Lang;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import test.wechat.service.WeixinService;

import java.util.List;

/**
 * .
 *
 * @author sunhao(sunhao.java@gmail.com)
 * @version V1.0, 16/3/4 下午1:22
 */
@Api(value = "微信用户API测试", description = "微信用户API测试")
@RestController
@RequestMapping("/weixin/user")
public class UserController {
    @Autowired
    private WeixinService weixinService;

    @ApiOperation(value = "修改用户备注", notes = "修改用户备注")
    @ApiResponses({@ApiResponse(code = 200, message = "修改用户备注成功")})
    @RequestMapping(value = "/update", method = RequestMethod.POST, produces = "application/json")
    public void updateUserAlias(@ApiParam(name = "openId", value = "用户标识") @RequestParam("openId") String openId,
                                @ApiParam(name = "alias", value = "新的备注名，长度必须小于30字符") @RequestParam("alias") String alias) {
        weixinService.updateUserAlias(openId, alias);
    }

    @ApiOperation(value = "获得用户信息", notes = "获得用户信息")
    @ApiResponses({@ApiResponse(code = 200, message = "获得用户信息成功")})
    @RequestMapping(value = "/{openId}/{lang}", method = RequestMethod.GET, produces = "application/json")
    public User getUser(@ApiParam(name = "openId", value = "用户标识") @PathVariable("openId") String openId,
                        @ApiParam(name = "lang", value = "语言") @PathVariable("lang") Lang lang) {
        return weixinService.getUser(openId, lang);
    }

    @ApiOperation(value = "获取全部关注用户", notes = "获取全部关注用户")
    @ApiResponses({@ApiResponse(code = 200, message = "发送模板消息成功")})
    @RequestMapping(value = "/list", method = RequestMethod.GET, produces = "application/json")
    public List<User> listUser() {
        return weixinService.listUsers();
    }
}
